"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasedbService = void 0;
const storage_1 = require("ee-core/storage");
const ps_1 = require("ee-core/ps");
const path_1 = __importDefault(require("path"));
/**
 * sqlite数据存储
 * @class
 */
class BasedbService {
    constructor(options) {
        Object.defineProperty(this, "dbname", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "db", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        Object.defineProperty(this, "storage", {
            enumerable: true,
            configurable: true,
            writable: true,
            value: void 0
        });
        const { dbname } = options;
        this.dbname = dbname;
        this.init();
    }
    /*
     * 初始化
     */
    init() {
        // 定义数据文件
        const dbFile = path_1.default.join((0, ps_1.getDataDir)(), "db", this.dbname);
        const sqliteOptions = {
            timeout: 6000,
            verbose: console.log
        };
        this.storage = new storage_1.SqliteStorage(dbFile, sqliteOptions);
        this.db = this.storage.db;
    }
    /*
     * change data dir (sqlite)
     */
    changeDataDir(dir) {
        // the absolute path of the db file
        const dbFile = path_1.default.join(dir, this.dbname);
        const sqliteOptions = {
            timeout: 6000,
            verbose: console.log
        };
        this.storage = new storage_1.SqliteStorage(dbFile, sqliteOptions);
        this.db = this.storage.db;
    }
}
exports.BasedbService = BasedbService;
BasedbService.toString = () => '[class BasedbService]';
